package com.example.demo.controller;

import com.example.demo.dao.model.SysToken;
import com.example.demo.service.ITokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("token")
public class SysTokenController {

    @Autowired
    private ITokenService tokenService;

    @GetMapping("/{id}")
    public SysToken getToken(@PathVariable("id") String id) {

        return this.tokenService.selectOne(id);
    }

    @GetMapping("/list")
    public List<SysToken> getTokens(String sessionId) {
        SysToken where = new SysToken();
        where.setSessionId(sessionId);

        return this.tokenService.selectMany(where);
    }


    @PostMapping("/new")
    public Boolean newToken(@RequestBody  SysToken token) {
        return this.tokenService.insertToken(token);
    }

    @PutMapping("/edit")
    public Boolean updateToken(@RequestBody SysToken token) {
        return this.tokenService.updateToken(token);
    }
}
